/********************************************************
  @brief: This class is supposed to store all the information about the Rss card from internet
  *       It's build with Qt, So to use it inside the LDF you may need to run a makefile project
  @author K. TANGAO [futurchercheur1@gmail.com] Qt demos and examples: RssListing adapted
  @date 06/01/2001
  @version 1.0
  **********************************************************/

#ifndef RSSBROWSING_H
#define RSSBROWSING_H

#include <QHttp>
#include <QWidget>
#include <QBuffer>
#include <QXmlStreamReader>


#include <string>

class QLineEdit;
class QPushButton;

// An item as a structure
typedef struct
        {
                std::string itemTitle;
                std::string itemDescription;
                bool imageAvailable;
                std::string imageUrl;
                std::string cardUrl;

        }itemFormat;



// An item as a class
class Item
{
        public:
                Item();
                ~Item();

                /*
                * @comment:print all the values of the Item
                * @param[in] void
                * @return void
                */
                void print();

                /*
                * @comment:change the values of the structure
                * @param[in] all the values without the boolean one
                * @return void
                */
                void updateItem(std::string itemTitleS, std::string itemDescriptionS, std::string imageUrlS, std::string cardUrlS);

                /*
                * @comment: get the item title
                * @param[in] void
                * @return	 string
                */
                std::string getItemTitle();

                /*
                * @comment: get the item description
                * @param[in] void
                * @return	 string
                */
                std::string getItemDescription();

                /*
                * @comment:  get the url of the image
                * @param[in] void
                * @return    string
                */
                std::string getImageUrl();

                /*
                * @comment:get the url of the card
                * @param[in] void
                * @return		string
                */
                std::string getCardUrl();

                /*
                * @comment:check if the image is available
                * @param[in] void
                * @return
                                true if available
                                false if not
                */
                bool isImageAvailable();

                /*
                * @comment:get the Item as a structure
                * @param[in] void
                * @return
                                itemFormat structure
                */
                itemFormat getItemAsStructure();

        protected:
                itemFormat myItemFormat;

};   // end of Item Class







class RssBrowsing : public QWidget
{
   Q_OBJECT

        public:

                //the constructor of our mini-browser
                //As input it takes the keyword [politics, technology, music, travel, music ...]
                RssBrowsing(std::string keyWord, QWidget *widget = 0);
                ~RssBrowsing();

                Item getItemByNumber(int number); // 1 <= number <= 10



       public slots:
                void fetch();
                void finished(int id, bool error);
                void readData(const QHttpResponseHeader &);
                void print();



        protected:

                //they keyword the user has to choose. politics, technology, Sport, Music or travel
                std::string keyWord;

                // thes items of the Xml file. 10 as usually
                Item* items;

                //the XML Reader
                QXmlStreamReader xml;
                //the connector
                QHttp http;

                //An Identification of the connection
                int connectionId;

                //The line Edit to get the keyword
                QLineEdit *lineEdit;
                // A button to abort a connexion
                QPushButton *abortButton;
                // A button to start a connexion
                QPushButton *fetchButton;
                // A button to print the items
                QPushButton *printButton;

                // Parse the Xml document
                void parseXml();

};


#endif // RSSBROWSING_H
